﻿using GrpcService;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Grpc.Core;
using Microsoft.Extensions.Hosting;

namespace NetCore6Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class GrpcController : ControllerBase
    {
        private string host = "localhost";
        private int port = 11001;
        public GrpcController()
        {
            
        }
        [HttpGet]
        /// <summary>
        /// Grpc客户端测试
        /// </summary>
        /// <returns></returns>
        public string GreetTest(string name) 
        {
            Channel channel = new(host, port, ChannelCredentials.Insecure);
            var cli= new Greeter.GreeterClient(channel);
            HelloRequest args=new HelloRequest() { Name= name };
            HelloReply res = cli.SayHello(args);
            return res?.Message ?? "no";
        }
    }
}
